<?php
// +----------------------------------------------------------------------
// | www模块基类
// +----------------------------------------------------------------------



class base_controller extends controller{

	protected $url;

	//构造函数
	public function _initialize() {
		header("Content-Type:text/html; charset=UTF-8");
		
		//if(!isset($_SESSION)) session_start();
		if ( get_magic_quotes_gpc() ) {
			if ($_POST) $_POST = stripslashes_deep($_POST);
			if ($_GET) $_GET = stripslashes_deep($_GET);
			if ($_COOKIE) $_COOKIE = stripslashes_deep($_COOKIE);
			if ($_REQUEST) $_REQUEST = stripslashes_deep($_REQUEST);
		}

		$this->url = $url = C('url');
		$this->assign('url', C('url'));
		$this->assign('tpl', $url['img']);

		//默认seo信息
		$this->assign('seo_title','Free Android & iPhone & iPad Wallpapers Download, Free Mobile Wallpapers Downloads');
		$this->assign('seo_keywords','Wallpapers, free wallpapers, android wallpapers, iPhone wallpapers, iPad wallpapers');
		$this->assign('seo_description','android & iPhone & iPad Wallpapers Download, download free mobile wallpapers and mobile pictuers');

		$this->assign('top_nav','index');
		if (method_exists($this, '_init'))  $this->_init();
	}

	//获取底部公共数据
	protected function getFooterData($map=array()){
		$cachename = 'public_footer_lists';
		$var = S($cachename);
		if(empty($var)){
			$var = array();

			//Top Categories
			$rows = M('category')->where("pid<>0")->order("view desc")->limit(8)->findAll();
			$var['foot_hot_category'] = M('category')->format($rows);

			//Hot Wallpapers
			$map = array();
			$field = "id,name,catid1,catid2,img,view,download,addtime,updatetime";
			$rows = M('image')->getList($map, 8, $field, 'view desc', '', true);
			$var['foot_hot_images'] = M('image')->format($rows,true);

			//Recommend Wallpapers
			$rows = M('image')->getList($map, 8, $field, 'rand()', 'catid2', true);
			$var['foot_recommend_images'] = M('image')->format($rows,true);

			//More From Wallpapers
			$var['foot_more_link'] = array(
				0 => array('name' => 'FeePHP', 'url' => 'http://www.feephp.com/'),
				1 => array('name' => 'Android Wallpaper', 'url' => 'http://www.5wallpaper.com/'),
				2 => array('name' => 'Iphone4 Wallpaper', 'url' => 'http://www.5wallpaper.com/'),
			);

			S($cachename,$var,3600);
		}

		$this->assign($var);
	}

	//获取左侧公共数据
	public function getLeftData(){
		$var = array();
		//分类
		$var['cates'] = $this->category->getChildTree(0);
		//字母列表
		$var['letters'] = $this->category->getLetterList();
		$this->assign($var);
	}

	//获取软件页缓存地址
	protected function getImageCacheFile($type,$id,$name){
		$md5 = md5(name2dir($name));
		$dir = substr($md5,0,1).'/'.substr($md5,1,1);
		$file = CACHE_PATH."/$type/$dir/$name-$id.html";
		return $file;
	}

	//检查是否命令行执行
	protected function chkCmd() {
		if(!IS_CLI && C('iscmd')){
			redirect404();
			//header('location:'.$this->url['www']);exit;
		}
	}

}